package com.supergo.manager.exception;

import com.supergo.http.HttpResult;
import io.jsonwebtoken.ExpiredJwtException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionResolver {

    /**
     * token认证异常
     * @param e
     * @return
     */
    @ExceptionHandler(AuthException.class)
    @ResponseBody
    public HttpResult authExceptionResolver(AuthException e){
        return HttpResult.error(401, e.getMessage());
    }

    @ExceptionHandler(ExpiredJwtException.class)
    @ResponseBody
    public HttpResult authExpiredExceptionResolver(ExpiredJwtException e){
        return HttpResult.error(402, "token过期，请重新登陆");
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public HttpResult systemException(Exception e){
        return HttpResult.error(500, e.getMessage());
    }


}
